package org.pewpew.client;

import org.pewpew.model.Player;
import org.pewpew.model.WorldState;

import android.app.Activity;
import android.util.Log;
import android.widget.TextView;

public class InfoPanelWorldObserver implements WorldObserver{
	private final Activity context;
	
	public InfoPanelWorldObserver(Activity mainActivity) {
		context = mainActivity;
	}
	
	public void update(GameModel gameModel, WorldState newState) {
		String username = gameModel.getPlayerName();
		Log.i ("PEW-observer", "Player username=" + username + " newState=" + newState.toJSON());
		TextView healthIndicator = (TextView) context.findViewById(R.id.HealthIndicator);
		TextView orientationIndicator = (TextView) context.findViewById(R.id.OrientationIndicator);
		
		Player player = newState.getUsers().get(username);
		Log.i ("PEW-observer", "Player is " + player);
		
		double health = player.getHealth();
		double orientation = player.getOrientation();
		
		healthIndicator.setText(String.valueOf(health));
		orientationIndicator.setText(String.valueOf(Math.round(orientation)));
	}

}
